package codeGen.core.jpa;

import codeGen.core.FreemarkerUtil;
import codeGen.core.model.TableModel;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class JpaControllerGen {
    public static String genCode(TableModel tModel, File output) {
        try {
            File controller = new File(output, tModel.getToClassName() + "Ctrl.java");
            FreemarkerUtil.genResource("jpa/controller.ftl", new FileOutputStream(controller), tModel);
            return "<li><a href=\"" + tModel.getAlias() + "/list.do\" class=\"list\" target=\"navTab\" rel=\"" + tModel.getToEntityName() + "List\" >" + tModel.getToClassName() + "</a></li>";
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }
}
